import React, { useState } from 'react'
import { Card , Breadcrumb , Form , Button , Radio , DatePicker } from 'antd'
import styles from './index.module.scss'
import { Link } from 'react-router-dom'
import { useDispatch} from 'react-redux'
import {getArticle} from '@/store/actions/article'
import ArticleTable from './components/ArticleTable'
import { status } from '@/enumeration/status'
import ArticleSelect from '@/components/ArticleSelect'
const { RangePicker } = DatePicker
export default function Article({history}) {
    const dispatch = useDispatch()
    let [params,setparams]=useState({})
    const onFinish = (values)=>{
      // console.log('表单值',values)
      values.status==='-1'&&(values.status=null)
      if(values.pubdate){
        values.begin_pubdate = values.pubdate[0].startOf('day').format('YYYY-MM-DD HH:mm:ss')
        values.end_pubdate = values.pubdate[1].endOf('day').format('YYYY-MM-DD HH:mm:ss')
        values.pubdate = null
      }
      setparams(values)
      // console.log('请求的值',params,values)
      dispatch(getArticle(values))
    }
  return (
    <div className={styles.root}>
      <Card title={
          <Breadcrumb>
            <Breadcrumb.Item>
              <Link to="/home">首页</Link>
            </Breadcrumb.Item>
            <Breadcrumb.Item>文章列表</Breadcrumb.Item>
          </Breadcrumb>
        }>
        <Form initialValues={{ status: '-1' }} onFinish={onFinish}>
          <Form.Item label="状态" name='status'>
            <Radio.Group>
                {/* <Radio key='-1' value={-1}>{1111}</Radio> */}
                { Object.keys(status).map(it=><Radio key={it} value={it}>{status[it]}</Radio>)}
            </Radio.Group>
          </Form.Item>
          <Form.Item label="频道" name='channel_id'>
            {/* <Select placeholder="请选择频道" style={{ width: 200 }}>
                {channelsList.channels.map(it=><Option key={it.id} value={it.id}>{it.name}</Option>)} 
            </Select> */}
            <ArticleSelect></ArticleSelect>
          </Form.Item>
          <Form.Item label="日期" name='pubdate'>
            <RangePicker />
          </Form.Item>
          <Form.Item>
             <Button type="primary" htmlType="submit">筛选</Button>
          </Form.Item>
        </Form>
      </Card>
      <ArticleTable history={history} params={params} ></ArticleTable>
    </div>
  )
}
